/**
 * Created by Ysssssss on 20/12/15.
 */
const app = getApp()
import { navBack, tipToast } from '../../../common/env';
import { getImportProductList, importProduct } from '../../../api/product';

Page({
    data: {
        searchInput: '',
        searchValue: '',
        checkedList: [],
    },
    onSearchValueChange(e) {
        this.setData({
            searchInput: e.detail,
        });
    },
    onSearch() {
        const { searchInput } = this.data
        this.setData({
            searchValue: searchInput
        })
    },

    async getProductListAction(e) {
        const [params, callback] = e.detail
        const list = await getImportProductList(params)
        callback && callback(list)
    },

    handleProductChecked(e) {
        const checkedList = e.detail
        this.setData({
            checkedList
        })
    },
    async productImportAction() {
        const { checkedList } = this.data
        if (!checkedList.length) {
            tipToast('请选择需要导入的商品')
            return;
        }
        const res = await importProduct({
            syncIds: checkedList
        })
        if (res) {
            app.event.trigger('productEdit')
            navBack()
        }
    }
})
